﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTSDAL.EntityFramework.Model;
using System.Data;

namespace UTSDAL.EntityFramework.DAO
{
    public class GenericDAO<TEntity> where TEntity:class
    {
        private UTSDBEntities entities = new UTSDBEntities();

        public virtual List<TEntity> selectAll()
        {
            return entities.CreateQuery<TEntity>("["+typeof(TEntity).Name+"]").ToList<TEntity>();
        }

        public virtual void insert(TEntity entity)
        {
            String entitySetName = entity.GetType().Name;
            entities.AddObject(entitySetName, entity);
            entities.SaveChanges();
            
        }

        public virtual void update(TEntity entity)
        {

            entities.SaveChanges();
        }

        public virtual void delete(TEntity entity)
        {
            entities.DeleteObject(entity);
            entities.SaveChanges();
        }

        /*
        public virtual TEntity findById(EntityKey key)
        {
            Object value = new Object();
            value = entities.TryGetObjectByKey(key,value);
            
        }
         */
    }
}
